package com.make.house.api.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by xujun on 2017/11/19.
 * 公共处理方法
 */
public class ManagerCommon {
    /**
     * 判断电话号码是否合法
     */
    public static boolean isPhoneNumberValid(String phoneNumber) {
        boolean isValid = false;
        // 区号+座机号码+分机号码：regexp="^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$"
        // 手机(中国移动手机号码)：regexp="^((\(\d{3}\))|(\d{3}\-))?13[456789]\d{8}|15[89]\d{8}"

        // 所有手机号码：regexp="^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[89]\d{8}"(新添加了158,159两个号段)
//		String expression = "^(((13)(\\d{9}))|((14)(0|5|7)(\\d{8}))|((15)(0|1|2|3|5|6|7|8|9)(\\d{8}))|((18)(0|1|2|3|5|6|7|8|9)(\\d{8}))|((17)(0)(\\d{8})))$";
        // String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";
        //手机号码以1开头的11位数
        String expression = "^((\\+86){0,1}((1)(\\d{10})))$";
        CharSequence inputStr = phoneNumber;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);

        // Pattern pattern2 = Pattern.compile(expression2);
        // Matcher matcher2 = pattern2.matcher(inputStr);
        if (matcher.matches()) {// || matcher2.matches()
            isValid = true;
        }
        return isValid;
    }
}
